#if (FEATURE_MODE == 0)
/**
 @file sys_usw_monitor.h

 @date 2009-10-19

 @version v2.0

 The file define APIs and types use in sys layer
*/
#ifndef _SYS_USW_MONITOR_H
#define _SYS_USW_MONITOR_H
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************
 *
 * Header Files
 *
 ***************************************************************/
#include "sal.h"
#include "ctc_const.h"
#include "ctc_vector.h"
#include "ctc_hash.h"
#include "ctc_monitor.h"
/***************************************************************
 *
 *  Defines and Macros
 *
 ***************************************************************/
#define SYS_MONITOR_MAX_CHANNEL 512
#define SYS_MONITOR_MAX_VIEWID 64
#define SYS_MONITOR_PRIO_CLASS_LEVEL_NUM 2 /*porttc mbsel num*/
#define SYS_MONITOR_PRIO_CLASS_NUM       8 /*porttc num*/
#define SYS_MONITOR_SC_NUM_MAX  4
#define SYS_MONITOR_QWM_NUM_MAX  32
#define SYS_MONITOR_LOG_MODE_CAUSER    0
#define SYS_MONITOR_LOG_MODE_VICTIM    1
#define SYS_MONITOR_LOG_MODE_ALL       2
#define SYS_MONITOR_LOG_MODE_VICTIM_PORT    2
#define SYS_MONITOR_LOG_MODE_VICTIM_PORT_TC 3
#define SYS_MONITOR_LOG_MODE_ALL_PORT       6
#define SYS_MONITOR_LOG_MODE_ALL_PORT_TC    7
struct sys_monitor_port_s
{
    uint8  valid;
    uint16 lport;
    uint16 ref_cnt;
};
typedef struct sys_monitor_port_s sys_monitor_port_t;

struct sys_monitor_path_config_s
{
    uint16 src_lport;
    uint16 dst_lport;
};
typedef struct sys_monitor_path_config_s sys_monitor_path_config_t;

struct sys_monitor_mb_thrd_s
{
    uint32 port_thrd[SYS_MONITOR_MAX_CHANNEL][2];/*0:min 1:max*/
    uint32 porttc_thrd[SYS_MONITOR_MAX_CHANNEL*SYS_MONITOR_PRIO_CLASS_LEVEL_NUM][2];/*0:min 1:max*/
    uint32 sc_thrd[4][2];
    uint32 total_thrd[2];
    uint32 c2c_thrd[2];
    uint32 critical_thrd[2];
    uint32 porttc_lvl_bmp[CTC_B2W_SIZE(SYS_MONITOR_MAX_CHANNEL*SYS_MONITOR_PRIO_CLASS_NUM)]; /*AT: porttc level 0/1 bitmap*/
};
typedef struct sys_monitor_mb_thrd_s sys_monitor_mb_thrd_t;


typedef struct sys_monitor_buf_scan_port_ctl_s
{
    uint8 port_sc_en_igs : 1;
    uint8 port_sc_en_egs : 1;
    uint8 port_tc_en_igs : 1;
    uint8 port_tc_en_egs : 1; /*for fast ecn*/
    uint8 queue_en       : 1; /*Only Egress*/
    uint8 port_en_igs    : 1;
    uint8 port_en_egs    : 1;
    uint8 rsv            : 1;
}sys_monitor_buf_scan_port_ctl_t;

/*from AT*/
struct sys_monitor_buf_scan_ctl_s
{
    uint16 total_en_igs  : 1;
    uint16 total_en_egs  : 1;
    uint16 queue_en      : 1; /*Only Egress*/
    uint16 port_tc_en_igs : 1; 
    uint16 port_tc_en_egs : 1; /*Engress for fast ecn*/
    uint16 port_en_igs   : 1; /*port_en_igs = 0 if all port_en_igs is 0 */
    uint16 port_en_egs   : 1; /*port_en_egs = 0 if all port_en_egs is 0 */
    uint16 sc_en_igs     : 1;
    uint16 sc_en_egs     : 1;
    uint16 port_sc_en_igs : 1;
    uint16 port_sc_en_egs : 1;
    uint16 c2c_en_igs     : 1;
    uint16 c2c_en_egs     : 1;
    uint16 critical_en_igs  : 1;
    uint16 critical_en_egs  : 1;
    uint16 round_trip_en    : 1; /*Ingress uc*/
    uint8  span_en          :1; /*Egress mc*/
    uint8  rsv              : 7;

    sys_monitor_buf_scan_port_ctl_t port[MAX_PORT_NUM_PER_CHIP]; /*record which port enabled ingress buffer scan*/
};
typedef struct sys_monitor_buf_scan_ctl_s sys_monitor_buf_scan_ctl_t;

struct sys_monitor_master_s
{
    ctc_monitor_fn_t func;
    void * user_data;
    uint32** buffer_stats; /*[SYS_MONITOR_MAX_CHANNEL][2]*/
    uint64** latency_stats; /*[SYS_MONITOR_MAX_CHANNEL][8]*/
    uint64** mburst_stats; /*[SYS_MONITOR_MAX_CHANNEL][8]*/
    uint64* mburst_timestamp; /*[SYS_MONITOR_MAX_CHANNEL]*/
    uint32 mburst_thrd[8]; /*level thrd of mb duration*/
    uint32 total_stats;
    void* p_buffer;
    void* p_buffer_stats; /* Arctic dma scan use*/
    sys_monitor_buf_scan_ctl_t* buf_scan; /*AT need soft query buffer stats*/
    void* p_latency;

    sys_monitor_port_t port_array[2][SYS_MONITOR_MAX_VIEWID];
    ctc_hash_t* p_monitor_hash;
    sal_mutex_t*  p_mutex;

    sys_monitor_mb_thrd_t* mb_thrd; /*min/max thrd for mb clear/occur*/
};
typedef struct sys_monitor_master_s sys_monitor_master_t;
extern sys_monitor_master_t *p_usw_monitor_master[CTC_MAX_LOCAL_CHIP_NUM_PP];

#define SYS_MONITOR_DBG_OUT(level, FMT, ...) \
    do { \
        CTC_DEBUG_OUT(monitor, monitor, MONITOR_SYS, level, FMT, ##__VA_ARGS__); \
    } while (0)

#define MONITOR_LOCK  \
    if (p_usw_monitor_master[lchip]->p_mutex) sal_mutex_lock(p_usw_monitor_master[lchip]->p_mutex)
#define MONITOR_UNLOCK  \
    if (p_usw_monitor_master[lchip]->p_mutex) sal_mutex_unlock(p_usw_monitor_master[lchip]->p_mutex)

#define SYS_MONITOR_VIEWID_VALID_CHECK(viewid) CTC_IS_BIT_SET(viewid, 6)
/***************************************************************
 *
 *  Functions
 *
 ***************************************************************/
extern int32
sys_usw_monitor_init(uint8 lchip, void* p_global_cfg);

extern int32
sys_usw_monitor_set_config(uint8 lchip, ctc_monitor_config_t *p_cfg);

extern int32
sys_usw_monitor_get_config(uint8 lchip, ctc_monitor_config_t *p_cfg);

extern int32
sys_usw_monitor_set_config2(uint8 lchip, ctc_monitor_config_type_t type, void* p_cfg);

extern int32
sys_usw_monitor_get_config2(uint8 lchip, ctc_monitor_config_type_t type, void* p_cfg);

extern int32
sys_usw_monitor_get_watermark(uint8 lchip, ctc_monitor_watermark_t *p_watermark);

extern int32
sys_usw_monitor_clear_watermark(uint8 lchip, ctc_monitor_watermark_t *p_watermark);

extern int32
sys_usw_monitor_set_global_config(uint8 lchip, ctc_monitor_glb_cfg_t* p_cfg);
extern int32
sys_usw_monitor_get_global_config(uint8 lchip, ctc_monitor_glb_cfg_t* p_cfg);

extern int32
sys_usw_monitor_register_cb(uint8 lchip, ctc_monitor_fn_t callback, void* userdata);

extern int32
sys_usw_monitor_get_cb(uint8 lchip, void **cb, void** user_data);
extern int32
sys_usw_monitor_deinit(uint8 lchip);

#ifdef __cplusplus
}
#endif

#endif

#endif

